﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using StockholmsStad.Business;
using StockholmsStad.Runtime.Serialization.DataContract.Enums;
using StockholmsStad.Utilities.Exceptions;
using StockholmsStad.Runtime.Serialization.DataContract;
using StockholmsStad.ServiceModel.Interfaces;

namespace StockholmsStad.ServiceModel.Services
{
    /// <summary>
    /// Detta är serviceimplementationsklassen för servicen IMinisterService.
    /// </summary>
    public class MinisterService : IMinisterService
    {
        #region IMinisterService Members

        //TODO Flytta alla metoder som har men Minster till denna tjänst

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="partOfName"></param>
        /// <param name="assignmentStartDate"></param>
        /// <param name="assignmentEndDate"></param>
        /// <param name="isActive"></param>
        /// <returns></returns>
        public List<Minister> GetMinisters(User user, string partOfName, DateTime? assignmentStartDate,
                            DateTime? assignmentEndDate, bool isActive)
        {
            try
            {
                var ministerBusiness = new MinisterBusiness(user);
                return ministerBusiness.GetMinisters(partOfName, assignmentStartDate, assignmentEndDate, isActive);
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }


        #endregion
    }
}
